package com.example.xyxwebbackend001.controller;

import com.example.xyxwebbackend001.service.FileStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.example.xyxwebbackend001.common.CommonResult;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/service/files")
public class FileUploadController {

    @Autowired
    private FileStorageService fileStorageService;

    // 通用上传接口
    @PostMapping("/upload/{module}")
    public CommonResult uploadFiles(
            @PathVariable String module,
            @RequestParam("files") MultipartFile[] files) {
        try {
            List<String> paths = fileStorageService.storeFiles(files, module);
            return CommonResult.success(paths);
        } catch (IOException e) {
            return CommonResult.error("文件上传失败: " + e.getMessage());
        }
    }
}
